package cn.ekuma.odbo.mobile.ui

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import cn.ekuma.odbo.mobile.R
import cn.ekuma.odbo.mobile.ui.recycler.AbstractEntityPagedListAdapter
//import com.google.android.material.tabs.TabLayout

abstract class AbstractOdboListFragment<T : Any,TV> : Fragment() {
    //protected lateinit var tabLayout:TabLayout
    protected lateinit var emptyLayout:FrameLayout
    protected lateinit var swipeRefreshLayout:SwipeRefreshLayout
    protected lateinit var listRecyclerView:RecyclerView

    protected lateinit var adapter: AbstractEntityPagedListAdapter<T>

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            initBundle(it)
        }
        adapter=createPageListAdapter()
    }

    open fun initBundle(bundle: Bundle){}

    abstract fun createPageListAdapter():AbstractEntityPagedListAdapter<T>

    open fun initTabView(){}

    open fun initEmptyLayout(emptyLayout: FrameLayout){}

    abstract fun initSwipeRefreshLayout(swipeRefreshLayout: SwipeRefreshLayout)

    abstract fun initListRecyclerView(listRecyclerView: RecyclerView)

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        val mainView=inflater.inflate(R.layout.fragment_list, container, false)
        //tabLayout=mainView.findViewById(R.id.tabLayout)
        emptyLayout=mainView.findViewById(R.id.emptyLayout)
        swipeRefreshLayout=mainView.findViewById(R.id.swipe_refresh)
        listRecyclerView=mainView.findViewById(R.id.list_view)

        initTabView()
        initEmptyLayout(emptyLayout)
        initSwipeRefreshLayout(swipeRefreshLayout)
        initListRecyclerView(listRecyclerView)
        listRecyclerView.adapter=adapter
        return mainView
    }



}